package vn.vfriends.id.bean;

import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author tuan@vfriends.vn
 */
@Named
@SessionScoped
public class OpenIdBean implements Serializable {

    private Logger logger = LoggerFactory.getLogger(SecurityBean.class);
    
    public String selectOPAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        try {
            HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
            HttpServletResponse resp = (HttpServletResponse) context.getExternalContext().getResponse();
            String identifier = req.getParameter("identifier");

            ServletContext servletContext = (ServletContext) context.getExternalContext().getContext();
            RequestDispatcher dispatcher = servletContext.getRequestDispatcher("/opconsumer");
            req.setAttribute("identifier", identifier);
            dispatcher.forward(req, resp);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.getMessage(), ""));
        }
        return "";
    }
}
